package com.gome.axwl.aoc.openApi.api.device;

import com.gome.axwl.aoc.entity.dto.DeviceDto;
import com.gome.axwl.aoc.entity.dto.PageParamDto;
import com.gome.axwl.aoc.facade.DeviceFacade;
import com.gome.common.utils.StringUtil;
import com.gome.commons.core.ErrorCode;
import com.gome.commons.core.ResultData;
import io.swagger.annotations.Api;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 *
 * 项目名称：gome-axwl-op-system-web
 * 类名称：DeviceController
 * 类描述：
 * 创建人：chengh
 * 创建时间：2018年5月4日11:00:12
 * @version
 */
@Api(tags="登录设备")
@RestController
@RequestMapping(value = "/device")
public class DeviceController {

    private final static Logger log = LoggerFactory.getLogger(DeviceController.class);

    @Autowired
    DeviceFacade deviceFacede;

    /**
     * 登录时更新账号-设备表
     * @param deviceDto
     * @param request
     * @return
     */
    @RequestMapping(value = "/addDeviceInfo", method = RequestMethod.POST)
    public ResultData addDeviceInfo(@RequestBody DeviceDto deviceDto , HttpServletRequest request){
        log.info("调用DeviceController.addDeviceInfo(登录时更新账号),参数为:" + deviceDto.toString());
        if(StringUtil.isEmpty(deviceDto.getCid()) || StringUtil.isEmpty(deviceDto.getDriverId()) || StringUtil.isEmpty(deviceDto.getEmpNo())){
            log.error("登录设备必传信息缺失.");
            return new ResultData(ErrorCode.FAILOR, "登录设备必传信息缺失.");
        }
        return  deviceFacede.addDeviceInfo(deviceDto);
    }


    /**
     * 根据driverIds集合获取用户登录设备信息集合
     * @param driverIds
     * @return
     */
    @RequestMapping(value = "/getDeviceInfo", method = RequestMethod.POST)
    public ResultData getDeviceInfoByDriverIds(@RequestBody List<String> driverIds){
        log.info("调用DeviceController.getDeviceInfoByAccountNos(根据driverIds集合获取用户登录设备信息集合),参数为:" + driverIds.toString());
        return  deviceFacede.getDeviceInfoByDriverIds(driverIds);
    }


    /**
     * 分页获取设备信息
     * @param pageParamDto
     * @return
     */
    @RequestMapping(value = "/getDeviceInfoByPage", method = RequestMethod.POST)
    public ResultData getDeviceInfoByPage(@RequestBody PageParamDto pageParamDto){
        log.info("调用DeviceController.getDeviceInfoByPage(分页查询设备信息),参数为:" + pageParamDto.toString());
        return  deviceFacede.getDeviceInfoByPage(pageParamDto);
    }

    @RequestMapping(value = "/testAddDeviceInfo", method = RequestMethod.GET)
    public ResultData testAddDeviceInfo(DeviceDto deviceDto , HttpServletRequest request){
        log.info("调用DeviceController.addDeviceInfo(登录时更新账号),参数为:" + deviceDto.toString());
        if(StringUtil.isEmpty(deviceDto.getCid()) || StringUtil.isEmpty(deviceDto.getDriverId()) || StringUtil.isEmpty(deviceDto.getEmpNo())){
            log.error("登录设备必传信息缺失.");
            return new ResultData(ErrorCode.FAILOR, "登录设备必传信息缺失.");
        }
        return  deviceFacede.addDeviceInfo(deviceDto);
    }



}
